import { getCategory } from '@/api/article'
import { getCategoryStorage, setCategoryStorage } from '@/utils/categoryStorage'

export default {
  namespaced: true,
  state () {
    return {
      tableData: JSON.parse(getCategoryStorage()) || [],
      navShowPublish: '',
      articleEditId: ''
    }
  },
  mutations: {
    setCategoryList (state, newData) {
      state.tableData = newData
      setCategoryStorage(JSON.stringify(newData))
    },
    setNavShowPublish (state, news) {
      state.navShowPublish = news
    },
    setArticleEditId (state, news) {
      state.articleEditId = news
    }
  },
  actions: {
    async categoryAction (context) {
      const res = await getCategory()
      res.data.forEach((e, index) => {
        e.serialNumber = index + 1
      })
      context.commit('setCategoryList', res.data)
    }
  },
  getters: {}
}
